Skip to content

Conversation

sckfranke
Copy link
Contributor

In modern versions of Git, git status will suggest using git restore in these cases. Also, in all other instances, the cheat sheet already lists git switch or git restore alternatives to git checkout.

Changes

  • Add git restore <file> and git restore --staged --worktree <file> as alternatives to git checkout <file> and git checkout HEAD <file>, respectively.

Context

Make the cheat sheet more consistent with git status. Also, when teaching Git to new users, using git switch and git restore consistently in place of git checkout arguably makes common workflows easier to understand; and being able to point those new users to the official cheat sheet without introducing new commands would be a big bonus.

In modern versions of Git, `git status` will suggest using `git restore` in these cases. Also, in all other instances, the cheat sheet already lists `git switch` or `git restore` alternatives to `git checkout`.
@jvns
Copy link
Collaborator

jvns commented Sep 19, 2025

This makes sense to me.

@christophprokop
Copy link

I was interested what exactly means "modern versions of git" in this context...

Release Notes of git 2.23.0:

Two new commands "git switch" and "git restore" are introduced to split "checking out a branch to work on advancing its history" and "checking out paths out of the index and/or a tree-ish to work on advancing the current history" out of the single "git checkout" command.

The official docs also list 2.23.0 as the oldest version of git switch and git restore
https://git-scm.com/docs/git-switch/2.23.0
https://git-scm.com/docs/git-restore/2.23.0

git 2.23.0 was released in August 2019
I hope most people have this available by now.
I support the suggestion to list the newer commands in the cheat sheet.

And thank you for the cheat sheet!

@To1ne
Copy link
Collaborator

To1ne commented Sep 23, 2025

I agree with @christophprokop. Personally I would like to double down on git-switch and git-restore. git-checkout is confusion to newcomers, and switch/restore make (arguably) more sense. Anyhow, this PR looks good to me.

Copy link
Collaborator

@To1ne To1ne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing in more git-restore.

@To1ne To1ne merged commit 93bfdfb into git:gh-pages Sep 23, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants